package com.slg.entity;

        import lombok.AllArgsConstructor;
        import lombok.Data;
        import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class JsonResponse<T> {
    private int code;
    private String msg;
    private T data;

    public JsonResponse(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    //封装一个统一成功的方法
    public static<T> JsonResponse<T> success(T data){
        return new JsonResponse<T>(Result.SUCCESS.code,Result.SUCCESS.msg,data);
    }

    //封装一个统一的失败方法
    public static<T> JsonResponse<T> error(){
        return new JsonResponse<T>(Result.ERROR.code,Result.ERROR.msg);
    }

    //封装一个自定义错误方法
    public static<T> JsonResponse<T> error(int code,String msg, T data){
        return new JsonResponse<T>(code,msg,data);
    }


}
